var com = require("../../utils/comm.js")
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      '/images/manage/top-1.jpg',
      '/images/manage/top-2.jpg',
      '/images/manage/top-3.jpg',
    ],
    indicatorDots: false,
    autoplay: false,
    interval: 3000,
    duration: 800,
    showView: true,

  },


  devicectr: function(e) {
    var x = com.authjust(2);
    if (x) {
      wx.navigateTo({
        url: '/pages/devicectr/devicectr',
      })
    } else {}
  },


  deviceclist: function(e) {
    var x = com.authjust(1);
    if (x) {
      wx.navigateTo({
        url: '/pages/deviceclist/deviceclist',
      })
    } else {}
  },

  turnToNbScan: function() {
    var x = com.authjust(1);
    if (x) {
      if (!app.globalData.hasLogin) {
        wx.navigateTo({
          url: "/pages/login/login"
        });
        return false;
      }
      let this_ = this;
      console.log('开始扫码');
      wx.showLoading({
        title: '加载中',
        mask: true
      });
      wx.scanCode({
        success: (res) => {
          console.log('扫码结果', res);
          console.log("index 生命周期 onload 参数 flag=" + util.getQueryString(res.path, 'deviceNo'))
          var deviceNo = util.getQueryString(res.path, 'deviceNo');
          util.request(api.DeviceNo, {
            deviceNo: deviceNo
          }).then(function(res) {
            console.log(res);
            if (app.globalData.hasLogin) {
              console.log("准备进入支付页面");
              wx.navigateTo({
                url: "/pages/devicePayment/devicePayment?query=" + JSON.stringify(res)
              });
              console.log("准备进入支付页面aaaa");
            } else {
              wx.navigateTo({
                url: "/pages/login/login"
              });
            }
          });
        },
        fail: (error) => {
          wx.hideLoading();
          console.log('请提供有效的二维码');
        },
        complete: () => {
          wx.hideLoading();
        }
      });
    }
  },

  deviceSetMealList: function(e) {
    var x = com.authjust(1);
    if (x) {
      wx.navigateTo({
        url: '/pages/deviceSetMealManage/deviceSetMealManage',
      })
    } else {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    showView: (options.showView == "true" ? true : false)

    var that = this
    var admin = wx.getStorageSync("usertype");
    that.setData({
      username: wx.getStorageSync('trueName'),
      admin: admin
    })



  },

  onChangeShowState: function() {
    var that = this;
    that.setData({
      showView: (!that.data.showView)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this

    that.setData({
      username: wx.getStorageSync('trueName')
    })

    com.getpower()

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})